<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="http://java.sun.com/jsp/jstl/myFn" prefix="myFn" %>
<html>
  <head>
  	<%@ include file="/jspf/public.jspf" %>
  	<script type="text/javascript">
  		$(function(){
  			$(".updBtn").click(function(){
  				// 获取操作的TD和复选框,如果位置近,可以采用临近选择器,如果远则siblings
  				var tdType=$(this).parent().siblings(".type");
  				var chkHot=$(this).parent().siblings("td[lang='hot']").children();
  				// 判断当前按钮状态
  				if($(this).val()=="更新"){
  					$(this).val("确认");
  					$(tdType).html("<input size='8' value="+ $(tdType).html() + " />");
  					$(chkHot).removeAttr("disabled");
  				}else{
  					$(this).val("更新");
  					$(tdType).html($(tdType).children().val()); 
  					$(chkHot).attr("disabled","disabled");
  					// 把数据发送给后台,需要同步更新
  					var id=$(this).parents("tr:first").attr("lang");
  					$.post("category_update.action",{id:id,type:$(tdType).html(),hot:$(chkHot).attr("checked")},function(result){
  						 alert(result);
  					});
  				}
  			});
  			$(".delBtn").click(function(){
  				alert("");
  			});
  		});
  	</script>
  </head>
  
  <body>     
  	   此页面是类别查询页面
  	 <form action="category_query.action" method="get">
  	          关键字:<input type="text" name="type"/><br />
  	    <input type="submit" value="给我搜" /> 
  	 </form>
  	 <c:if test="${not empty requestScope.categoryList}">
	  	 <table border="1" style="width: 600px;">
	  	 	<tr>
	  	 		<td>编号</td>
	  	 		<td>类别名称</td>
	  	 		<td>是否热点</td>
	  	 		<td>管理员</td>
	  	 		<td>更新</td>
	  	 		<td>删除</td>
	  	 	</tr>
	  	 		<c:forEach items="${requestScope.categoryList}" var="category" varStatus="num">
		  	 		<tr lang="${category.id}">
			  	 		<td>${num.count}</td>
			  	 		<td class="type"><c:out value="${category.type}" default="　" /></td>
			  	 		<td lang="hot">
			  	 		   <input type="checkbox" name="hot" value="true" disabled="disabled" 
			  	 		   <c:if test="${category.hot}">
			  	 		   checked="checked"
			  	 		   </c:if> />
			  	 		</td>
			  	 		<td><c:out value="${category.account.login}" default="　" /></td>
			  	 		<td>
				  	 		<input type="button" value="更新" class="updBtn" />
			  	 		</td>
			  	 		<td>
			  	 			<input type="button" value="删除" class="delBtn" />
			  	 		</td>
		  	 		</tr>
		  	 	</c:forEach>
	  	 </table>
  	 </c:if>
  </body>
</html>
